<template>
	<view class="tabbox flexspb">
		<view @click="tolink(item.path)" class="centtab flexcolumn" :class="{ 'tabactive': index === tab }"
			v-for="item, index in tabList" :key="index">
			<image class="tab_img" :src="index == tab ? `/${item.selectedIconPath}` : `/${item.iconPath}`"></image>
			<view class="tab_text">{{ item.title }}</view>
		</view>
	</view>
</template>

<script>
	const tabList_1 = [{
			title: "首页",
			path: "pages/committee/home/index",
			iconPath: "static/img/tabbar/home.png",
			selectedIconPath: "static/img/tabbar/home_selected.png"
		},
		{
			title: "提建议",
			path: "pages/committee/advise/index",
			iconPath: "static/img/tabbar/advise.png",
			selectedIconPath: "static/img/tabbar/advise.png"
		},
		{
			title: "消息",
			path: "pages/committee/message/index",
			iconPath: "static/img/tabbar/message.png",
			selectedIconPath: ""
		},
		{
			title: "我的",
			path: "pages/committee/mine/index",
			iconPath: "static/img/tabbar/mine.png",
			selectedIconPath: "static/img/tabbar/mine_selected.png"
		}
	];
	const tabList_2 = [{
			title: "首页",
			path: "pages/crowd/home/index",
			iconPath: "static/img/tabbar/home.png",
			selectedIconPath: "static/img/tabbar/home_selected.png"
		},
		{
			title: "群众建议广场",
			path: "pages/crowd/opinion/index",
			iconPath: "static/img/tabbar/opinion.png",
			selectedIconPath: "static/img/tabbar/opinion.png"
		},
		{
			title: "我的",
			path: "pages/mine/index",
			iconPath: "static/img/tabbar/mine.png",
			selectedIconPath: "static/img/tabbar/mine_selected.png"
		}
	]
	export default {
		name: 'tabbox', //tabar切换栏
		data() {
			return {
				tabList: [],
				tab: 0, //当前默认选中
			}
		},
		async created() {
			if (uni.getStorageSync('identify') == 'tom') {
				this.tabList = tabList_2;
			} else {
				this.tabList = tabList_1;
			}
			// 隐藏默认的taar
			// this.rest.setTabBar(false);
			// 同步当前页面路由
			await this.setchange();
		},
		methods: {
			// 同步当前页面路由
			setchange() {
				let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				let curRoute = routes[routes.length - 1].route // 获取当前页面路由，也就是最后一个打开的页面路由
				this.tab = this.tabList.findIndex(em => em.path === curRoute)
			},
			// 关闭所有页面跳转
			tolink(path) {
				this.rest.jump('swt', '/' + path);
			}
		}
	}
</script>

<style lang="less" scoped>
	.tabbox {
		// width: 100vw;
		background-color: #ffffff;
		box-shadow: 0 10rpx 40rpx #EFEFEF;
		border-top: 1rpx solid #EFEFEF;
		height: 130rpx;
		box-sizing: border-box;
		padding: 20rpx 0 40rpx;

		.centtab {
			flex: 1;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;

			.tab_img {
				width: 48rpx;
				height: 48rpx;
			}

			.tab_text {
				font-size: 20rpx;
				line-height: normal;
				margin-top: 6rpx;
			}

			.tabactive {
				color: #d81d06;
			}
		}

	}
</style>